home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: heldLockEntry.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:51 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "latch.h"
- #include "bf.h"
- #include "volume.h"
- #include "trans.h"
- #include "threadstate.h"
- #include "thread_funcs.h"
- #include "lm_intfuncs.h"
- #include "lm_extfuncs.h"
- #include "lock_globals.h"
- #include "thread_globals.h"
-
-
- static LIST AgeList;
-
- #define LOCK_WAIT_UNIT 10 /* seconds */
-
- void
- ageLocks()
- {
- LOCKENTRY *lockEntry, *next;
-
- initializeList( &AgeList );
- /* Sleep right away, after startup, so the rest of
- * initializeServer() gets done.
- */
-
- for(;;) {
- /* every minute, age the locks on the list by one minute */
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("ageLocks sleeps for %d sec",
- LOCK_WAIT_UNIT));
-
- Sleep(LOCK_WAIT_UNIT);
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("ageLocks wakes up"));
-
- lockEntry = (LOCKENTRY *) FIRST_LIST_ELEMENT( &AgeList );
-
- if(LIST_EMPTY( &AgeList)) {
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("AgeList EMPTY"));
- } else {
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("lock-aging tick"));
- }
- while(lockEntry != NULL) {
- TRPRINT(TR_LOCK, TR_LEVEL_1,
- ("lock request at age %d", lockEntry->time2wakeup));
- next = (LOCKENTRY *) NEXT_LIST_ELEMENT( &(lockEntry->ageList));
- if(lockEntry->flags & LOCK_GRANTED) {
- /* skip it - just let it be removed from the list */
- } else if(--(lockEntry->time2wakeup) <= 0) {
-
- TRPRINT(TR_LOCK, TR_LEVEL_1,
- ("lock request %x, flags 0x%x, hdr 0x%x dies of old age",
- lockEntry, lockEntry->flags, lockEntry->lockHeader));
- /* NB: there is exactly ONE element on the threadList! */
- SM_ASSERT(LEVEL_1,
- (LIST_NOT_EMPTY( &(lockEntry->threadList) )));
-
- if(lockEntry->flags & LOCK_UPGRADE) {
- LOCKENTRY *master = (LOCKENTRY *)(lockEntry->lockHeader);
- SM_ASSERT(LEVEL_1,
- (master ->flags & LOCK_UPGRADE_PENDING));
- master->flags &= ~LOCK_UPGRADE_PENDING;
- }
- freeLockEntry(lockEntry, esmLOCKBUSY);
- }
- lockEntry = next;
- }
- }
- }
-
- int
- awaitLock(int lock_wait_units, LOCKENTRY *lockEntry, int state)
- {
- lockEntry->time2wakeup = lock_wait_units;
- listEnq(&AgeList, &(lockEntry->ageList));
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("lock %x waits, age %d", lockEntry,
- lockEntry->time2wakeup));
- /*
- * put the thread on the wait list for this lock
- */
- return waitList(&(lockEntry->threadList), THREAD_LOCK_WAIT);
- }
-
-
- LOCKENTRY
- *heldLockEntry (
-
- register TRANSREC *transRec,
- LOCKHEADER *lockHeader,
- LOCKMODE requestMode,
- FLAGS flags
- )
- {
-
- register LOCKENTRY *lockEntry;
-
-
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("supremum:%s requestMode:%s",
- GETMODE(lockHeader->supremum), GETMODE(requestMode)));
-
- /*
- * check to see if the lock can be granted
- */
- if ((LM_Compat[lockHeader->supremum][requestMode]) &&
- (LIST_EMPTY( &(lockHeader->waitList) )) &&
- (LIST_EMPTY( &(lockHeader->upgradeList) ))) {
-
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("lock request compatible"));
-
- /*
- * Get an new lock entry record
- */
- if ((lockEntry =
- newLockEntry(transRec, lockHeader, GRANT_LIST, requestMode))==NULL){
- return(NULL);
- }
-
- /*
- * check to see if we have a new supremum
- */
- if (!LM_Compat_Upgrade[requestMode][lockHeader->supremum]) {
-
- lockHeader->supremum = LM_Supremum[requestMode][lockHeader->supremum];
- }
- /*
- * initialize lock header information
- */
- lockHeader->modeCount[requestMode]++;
- lockHeader->lockCount++;
-
- /*
- * return a pointer to the lock entry
- */
- return(lockEntry);
-
- } else {
-
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("request mode is not compatible"));
-
- /*
- * check to see if the flags are instant or nowait
- */
- if ((flags & LOCK_NOWAIT) || (flags & LOCK_INSTANT)) {
-
- SM_ERROR(TYPE_USER, esmLOCKBUSY);
- return(NULL);
- }
-
- /*
- * check the deadlock
- */
- if (checkDeadlock(transRec,
- (LOCKENTRY *) FIRST_LIST_ELEMENT( &(lockHeader->grantedList) ))) {
-
- return(NULL);
- }
-
- /*
- * allocate a new entry to the request
- */
- if ((lockEntry =
- newLockEntry(transRec, lockHeader, WAIT_LIST, requestMode))==NULL){
- return(NULL);
- }
-
- /*
- * check to see if the transaction is privileged
- */
- if (transRec->privilege & TRANSPRIV_PREEMPT) {
-
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("TRANSPRIV_PREEMT"));
- /*
- * put the request on the front of the list
- */
- listMovePush( &(lockHeader->waitList), &(lockEntry->headerList.list) );
-
- /*
- * blow the active transactions away
- */
- preemptLock(lockHeader, requestMode);
- }
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("LOCK_TIMEOUT"));
-
- if( awaitLock(transRec->lock_timeout,
- lockEntry, THREAD_LOCK_WAIT) == esmNOERROR) {
- return lockEntry;
- } else {
- return NULL;
- }
- }
- }
-